﻿using System.Windows.Controls;
using System.Windows.Input;
using SilverlightApplication.LanguageResources;
using SilverlightApplication.UIControls;
using LinqToAmazonSL;

namespace SilverlightApplication
{
    public partial class DVDBasicPanel : UserControl, ISearchPanelContent
	{
        SearchPanels parent;

		public DVDBasicPanel(SearchPanels parent)
		{
			// Required to initialize variables
			InitializeComponent();

            bsDVDTitle.Text = LanguageLoader.GetString("bsdvdTitle");
            bsDVDActor.Text = LanguageLoader.GetString("bsdvdActor");
            bsDVDDirector.Text = LanguageLoader.GetString("bsdvdDirector");

            this.parent = parent;
		}

        public SearchCriteria GetSearchCriteria()
        {
            SearchCriteria criteria = new SearchCriteria();
            AmazonDVD dvd = new AmazonDVD();

            dvd.Title = txbDVDTitle.Text.Trim();
            dvd.Actor = txbDVDActor.Text.Trim();
            dvd.Director = txbDVDDirector.Text.Trim();
            criteria.OrderBy = OrderClass.None;
            criteria.Item = dvd;

            return criteria;
        }

        public bool FieldsValidate()
        {
            return !txbDVDTitle.Text.Equals(string.Empty)
                || !txbDVDActor.Text.Equals(string.Empty)
                || !txbDVDDirector.Text.Equals(string.Empty);
        }

        public void ClearFields()
        {
            txbDVDTitle.Text = "";
            txbDVDActor.Text = "";
            txbDVDDirector.Text = "";
        }

        private void KeyPress(object sender, KeyEventArgs e)
        {
            if (Key.Enter.Equals(e.Key))
            {
                parent.beginSearch();
            }
        }
	}
}